#!/usr/bin/env bash

# 定义变量
IMAGE_NAME="renren/fast"
CONTAINER_PORT="8088"
CONTAINER_NAME="renren-fast"-${CONTAINER_PORT}

# 进入存放 Dockerfile 的目录下
cd ${WORKSPACE}/target/docker

# 构建Docker镜像
# docker build -t ${IMAGE_NAME} .

# 推送Docker镜像
# docker push ${IMAGE_NAME}

# 删除 Docker 容器
cid=$(docker ps | grep ${IMAGE_NAME} | awk '{print $1}')
if [[ x"$cid" != x ]]
    then
    docker rmi -f ${cid}
fi

# 删除 Docker 容器
cid=$(docker ps | grep ${CONTAINER_NAME} | awk '{print $1}')
if [[ x"$cid" != x ]]
    then
    docker rm -f ${cid}
fi

#启动 Docker 容器
docker run -d -p ${CONTAINER_PORT}:8080 --name ${CONTAINER_NAME} ${IMAGE_NAME}